#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    setupActions();


    QFile *file = new QFile(QDir::currentPath() + "/algorithms.list");
    file->open(QIODevice::ReadOnly);

    QDataStream in(file);
    in >> algorithms;
    file->close();

    for (int i=0; i<algorithms.count(); i++){
        if (!AlgorithmStrings.contains(algorithms[i].name))
            AlgorithmStrings << algorithms[i].name;
        if (!OptimizationStrings.contains(algorithms[i].optimization))
            OptimizationStrings << algorithms[i].optimization;
    }


    taskListWidget = new TaskListWidget();
    inputSettingsWidget = new InputSettingsWidget();
    manualInputWidget = new ManualInputWidget();

    upSplitter = new QSplitter(Qt::Horizontal);
    upSplitter->addWidget(inputSettingsWidget);
    upSplitter->addWidget(manualInputWidget);

    mainSplitter = new QSplitter(Qt::Vertical);
    mainSplitter->addWidget(upSplitter);
    mainSplitter->addWidget(taskListWidget);

    setCentralWidget(mainSplitter);

    algorithmEditDialog = 0;
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::Input()
{
    inputSettingsWidget->setVisible(false);
}

void MainWindow::LoadTypeLists()
{

}

void MainWindow::setupActions()
{
    connect(ui->editAlgorithmAction, SIGNAL(triggered()), this, SLOT(EditAlgoritms()));
}

void MainWindow::EditAlgoritms()
{
    if (algorithmEditDialog == 0 ) {
        algorithmEditDialog = new AlgorithmEditDialog(this);
        algorithmEditDialog->prepare();
    }

    algorithmEditDialog->exec();
}
